package lol.clann.minecraft.springboot.plugin.bukkit.impl;

import lol.clann.minecraft.springboot.api.annotation.compatibility.CompatibilityChecked;
import lol.clann.minecraft.springboot.api.bukkit.utils.ChatSerializerUtils;
import lol.clann.minecraft.springboot.bukkit.utils.BukkitUtils;
import net.minecraft.server.v1_7_R4.ChatSerializer;
import net.minecraft.server.v1_7_R4.IChatBaseComponent;
import org.springframework.stereotype.Service;

/**
 * @author pyz
 * @date 2018/10/7 下午4:26
 */
@Service
@CompatibilityChecked
public class ChatSerializerUtilsImpl_all implements ChatSerializerUtils {

    @Override
    public <T> String serialize(T iChatBaseComponent) {
        if (BukkitUtils.getBukkitVersionNumber() < 10800) {
            return ChatSerializer.a((IChatBaseComponent) iChatBaseComponent);
        } else {
            return net.minecraft.server.v1_8_R3.IChatBaseComponent.ChatSerializer.a((net.minecraft.server.v1_8_R3.IChatBaseComponent) iChatBaseComponent);
        }
    }

    @Override
    public <T> T deserialize(String content) {
        if (BukkitUtils.getBukkitVersionNumber() < 10800) {
            return (T) ChatSerializer.a(content);
        } else if (BukkitUtils.getBukkitVersionNumber() < 10900) {
            return (T) net.minecraft.server.v1_8_R3.IChatBaseComponent.ChatSerializer.a(content);
        } else {
            return (T) net.minecraft.server.v1_9_R2.IChatBaseComponent.ChatSerializer.b(content);
        }
    }

}
